package com.onlookers.server;

import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

public class Report {

	public String title;

	public String link;

	public String description;

	public String pubDate;

	public String source;

	public String author;

	public Report(String title, String link, String description,
			String pubDate, String source, String author) {
		this.title = title;
		this.link = link;
		this.description = description;
		this.pubDate = pubDate;
		this.source = source;
		this.author = author;

		genKeyWords(title, keyWords);
		genReportTime(this);
	}
	
	public static void genReportTime(Report report) {
		SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss", Locale.US);
		try {
			report.reportTime = sdf.parse(report.pubDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void genKeyWords(String value, Set<String> keyWords) {
		IKSegmenter iks = new IKSegmenter(new StringReader(value), true);
		Lexeme lexem;
		try {
			while ((lexem = iks.next()) != null) {
				keyWords.add(lexem.getLexemeText());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public String toString() {
		return "Report## title:" + title + ", date:" + pubDate + "source:" + source + "\n";
	}

	String url;
	Date reportTime;
	Set<String> keyWords = new HashSet<String>();

	public void addKeyWord(String key) {
		keyWords.add(key);
	}

	public Set<String> getKeyWords() {
		return keyWords;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Date getReportTime() {
		return reportTime;
	}

	public void setReportTime(Date reportTime) {
		this.reportTime = reportTime;
	}

}
